package com.app.budgetbook;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;

import com.app.budgetbook.db.dbAdapter;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MonthlyCal extends Activity{
	
	protected String month;
	protected int food=0;
	protected int transport=0;
	protected int family=0;
	protected int accessories=0;
	protected int health=0;
	protected int entertainment=0;
	protected String sfood;
	protected String stransport;
	protected String sfamily;
	protected String saccessories;
	protected String shealth;
	protected String sentertainment;
	private TextView tfood;
    private TextView ttransport;
    private TextView thealth;
    private TextView taccessories;
    private TextView tfamily;
    private TextView tentertainment;
	protected String monthid;
	protected String monthchat="1";
	protected String[] temp; 
	
	 private Long mRowId;
	private dbAdapter dbHelper;
	private Cursor cursor;
	
	   @Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.doverview);
		
		tfood = (TextView) findViewById(R.id.dofood);
        ttransport = (TextView) findViewById(R.id.dotransport);
        thealth = (TextView) findViewById(R.id.dohealth);
        taccessories = (TextView) findViewById(R.id.doaccessories);
        tfamily = (TextView) findViewById(R.id.dofamily);
       tentertainment = (TextView) findViewById(R.id.doentertainment);
		
		dbHelper = new dbAdapter(MonthlyCal.this);
        dbHelper.open();
        
        month=getIntent().getStringExtra("month");
       // Toast.makeText(this,"hello"+month,Toast.LENGTH_LONG).show();
        if(month.equalsIgnoreCase("January"))
        {
        	monthid="01";
        }
        if(month.equalsIgnoreCase("February"))
        {
        	monthid="02";
        }
        if(month.equalsIgnoreCase("March"))
        {
        	monthid="03";
        }
        if(month.equalsIgnoreCase("april"))
        {
        	monthid="04";
        }
        if(month.equalsIgnoreCase("May"))
        {
        	monthid="05";
        }
        if(month.equalsIgnoreCase("June"))
        {
        	monthid="06";
        }
        if(month.equalsIgnoreCase("July"))
        {
        	monthid="07";
        }
        if(month.equalsIgnoreCase("August"))
        {
        	monthid="08";
        }
        if(month.equalsIgnoreCase("September"))
        {
        	monthid="09";
        }
        if(month.equalsIgnoreCase("October"))
        {
        	monthid="10";
        }
        if(month.equalsIgnoreCase("November"))
        {
        	monthid="11";
        	  //Toast.makeText(this,"if",Toast.LENGTH_SHORT).show();
        	
        }
        if(month.equalsIgnoreCase("December"))
        {
        	monthid="12";
        }
        
            cursor  = dbHelper.fetchAllBudget();
            startManagingCursor(cursor);
            
            while(cursor.moveToNext())
            {
            		
            	String d=cursor.getString(1);
            	temp = d.split("-");
            	//int dmonth=Integer.parseInt(temp[0]);
            	if(monthid.equals(temp[0]))
            	{
            		Toast.makeText(this,"month equals",Toast.LENGTH_SHORT).show();
            		food+=Integer.parseInt(cursor.getString(2));
            		transport+=Integer.parseInt(cursor.getString(3));
            		health+=Integer.parseInt(cursor.getString(4));
            		accessories+=Integer.parseInt(cursor.getString(6));
            		entertainment+=Integer.parseInt(cursor.getString(5));
            		family+=Integer.parseInt(cursor.getString(7));
            		//sfood=cursor.getString(2);
            	}
            	sfood=Integer.toString(food);
            	stransport=Integer.toString(transport);
            	shealth=Integer.toString(health);
            	saccessories=Integer.toString(accessories);
            	sentertainment=Integer.toString(entertainment);
            	sfamily=Integer.toString(family);
            	
            	tfood.setText(sfood);
            	ttransport.setText(stransport);
            	thealth.setText(shealth);
            	taccessories.setText(saccessories);
            	tentertainment.setText(sentertainment);
            	tfamily.setText(sfamily);
            	
            	            //	Toast.makeText(this,"change"+sfood,Toast.LENGTH_LONG).show();
            }
		
            Button mchatview = (Button)findViewById(R.id.mchartbutton);
            mchatview.setOnClickListener(new View.OnClickListener() {
    			
    			@Override
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				Intent intent = new Intent(MonthlyCal.this, Dchart.class);
    					intent.putExtra("monthchat2", monthchat);
    			        intent.putExtra("mfood", sfood);
    			        intent.putExtra("mtransport", stransport);
    			        intent.putExtra("mhealth", shealth);
    			        intent.putExtra("maccessories", saccessories);
    			        intent.putExtra("mentertainment", sentertainment);
    			        intent.putExtra("mfamily", sfamily);
    			       startActivity(intent); 
    			       //Toast.makeText(parent.getContext(),  
    			    	 //        "is Selected", Toast.LENGTH_LONG).show();
    				//bClick.start();
    			}
    		});

	}

	  
}
